<template>
    <div class="login">
        <div class="title">账号密码登录</div>
        <div class="username">用户名：<input type="text" v-model="username"></div>
        <div class="password">密码：<input type="text" v-model="password"></div>
        <button @click="login">登录</button>
    </div>
</template>
<script setup lang="ts" name="Login">
import { ref } from 'vue';
import axios from 'axios';
import { useRouter } from 'vue-router';
let password=ref("");
let username=ref("");
const router=useRouter();
async function login(){
    let {data}=await axios.post("http://localhost:8080/login",{
        username: username.value,
        password: password.value
    })
    if(data.code==0){
        alert(data.msg);
    }
    else{
        router.push('/home')
    }
    console.log(data.data);
}

</script>

<style scoped>
    .login{
        position: absolute;
        width: 500px;
        height: 150px;
        top: 50%;
        left: 50%;
        transform: translate(-50%,-50%);
        border: 1px solid black;

        .title{
            text-align: center;
        }
        .username{
            margin-top: 10px;
            text-align: center;
        }
        .password{
            margin-top: 10px;
            margin-bottom: 10px;
            text-align: center;
            input{
                margin-left: 15px;
            }
           
        }
        button{
            margin-top: 10px;
            margin: 0 auto;
            width: 50px;
            display: block;
        }
    }
</style>